<template>
	<view class="payment">
		<view
			style="width: 662rpx;background: #FFFFFF;border-radius: 16rpx;text-align: center;margin:0 20rpx 156rpx;padding:86rpx 24rpx 24rpx;">
			<view style="font-size: 56rpx;font-weight: bold;">￥{{prices}}</view>
			<view style="padding:70rpx 0 60rpx;">共计1个商品，该师傅报价</view>
			<view class="flexJusp" style="border-top:2rpx solid #F2F2F2;padding:24rpx 0 16rpx;">
				<view style="color: #666666;">师傅报价</view>
				<view>￥{{price}}</view>
			</view>
			<view class="flexJusp" @click="coupon">
				<view style="color: #666666;">优惠券</view>
				<view>-￥{{couponNum}}</view>
			</view>
		</view>
		<view class="buttons" @click="zhifu">确认支付</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				userId: '',
				price: 0,
				prices: 0,
				couponNum: 0,
				couponsId:''
			};
		},
		onLoad(option) {
			this.id = option.id
			this.price = option.price
			this.userId = option.userId
			this.heji()
		},
		methods: {
			coupon() {
				var that = this
				uni.navigateTo({
					url: '/pages/PlaceOrder/coupon/coupon?kind=1&price=' + this.price,
					events: {
						acceptDataFromOpenedPages: (data) => {
							console.log(data, '---------')
							that.couponNum = data.jianprice
							that.couponsId = data.id
							that.heji()
						},
					},
				})
			},
			heji(){
				var price = parseFloat(this.price)
				price = price - parseFloat(this.couponNum)
				this.prices = price
			},
			zhifu() {
        let that = this
				this.$httpapi('addPackageshifu', 'POST', {
					orderId:this.id,
					userid:this.userId,
					price:this.prices,
					couponsId:this.couponsId,
					moshi:'2'
				}).then(res => {
					if (res.code == 200) {
            if (res.data) {
              if (res.data.status === 1) {
                that.$utils.saveSyncTime()
                uni.showToast({
                  title: res.data.msg,
                  duration: 1500,
                  icon: 'none'
                });
                setTimeout(() => {
                  uni.switchTab({
                    url: '/pages/myOrder/myOrder'
                  })
                }, 1500)
              } else {
                uni.requestPayment({
                  provider: 'wxpay',
                  timeStamp: res.data.timeStamp,
                  nonceStr: res.data.nonceStr,
                  package: res.data.package,
                  signType: res.data.signType,
                  paySign: res.data.paySign,
                  success: function (rexx) {
                    that.$utils.saveSyncTime()
                    uni.switchTab({
                      url: '/pages/myOrder/myOrder'
                    })
                  },
                  fail: function (err) {
                  }
                });
              }
            } else {
              uni.showToast({
                title: res.msg,
                icon: 'none'
              })
            }
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F6FA;
	}

	.payment {
		padding: 20rpx 0 0;

		.buttons {
			text-align: center;
			margin: 156rpx auto 0;
			width: 614rpx;
			height: 88rpx;
			background: linear-gradient(180deg, #2089FF 0%, #11ACEF 100%);
			border-radius: 44rpx;
			color: #FFFFFF;
			line-height: 88rpx;
		}
	}
</style>
